<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/19
 * Time: 18:59
 */

namespace app\index\model;
use think\Model;
use think\Db;
class CashModel extends Model{
    // 确定链接表名
    protected $table = 'snake_user_cash';
    public function add($param){
        $user_id=session('user_id');
        if($param['money']==0) return msg(-1, '', '提现金额格式错误');
        if(!is_numeric($param['money'])) return msg(-1, '', '提现金额格式错误');
        $model=new UsersModel();
        $user=$model->getOne($user_id);
        if($user['user_money']<$param['money']) return msg(-1, '', '余额不足');
        $map=array(
            'user_id'=>$user_id,
            'mobile'=>$param['mobile'],
            'money'=>$param['money'],
            'bank_name'=>$param['bank_name'],
            'bank_card'=>$param['bank_card'],
            'realname'=>$param['realname'],
            'addtime'=>time(),
        );
        try{
            $num=$this->save($map);
            if(false === $num){
                return msg(-1, '', '提交失败');
            }
            $model->updateUser(array('user_money'=>$user['user_money']-$param['money']),$user_id);
            return msg(1,url('user/index'),'提交成功');
        }catch(\Exception $e){
            return msg(-1, '', $e->getMessage());
        }
    }
}